package com.why.zing.payapi.controller;

import com.why.zing.common.domain.ZingResult;
import com.why.zing.payapi.model.*;
import com.why.zing.payapi.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 订单控制器
 *
 * @author 王洪玉
 * @date 2020/1/12
 */
@Api(tags = "订单")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;


    @ApiOperation("支付宝扫码支付")
    @PostMapping(value = "/aliPay")
    public ZingResult<PayOrderResponse> aliPay(@Validated PayOrderRequest payOrderRequest) {
        PayOrderResponse payOrderResponse = orderService.aliPay(payOrderRequest);
        return ZingResult.success(payOrderResponse);
    }

    @ApiOperation("查询订单")
    @GetMapping(value = "/queryOrder")
    public ZingResult<OrderQueryResponse> queryOrder(@RequestParam(value = "orderNo") String orderNo) {
        OrderQueryResponse orderQueryResponse = orderService.queryOrder(orderNo);
        return ZingResult.success(orderQueryResponse);
    }

    @ApiOperation("申请退款")
    @PostMapping(value = "/refundOrder")
    public ZingResult<OrderRefundResponse> refundOrder(@RequestBody OrderRefundRequest orderRefundRequest) {
        OrderRefundResponse orderRefundResponse = orderService.refundOrder(orderRefundRequest);
        return ZingResult.success(orderRefundResponse);
    }
}
